package birdsVSZombiesClient.GUI;

import ddf.minim.AudioSample;
import ddf.minim.AudioSnippet;
import processing.core.PConstants;
import processing.core.PFont;
import processing.core.PImage;

public class BVZRectButton extends BVZButton {
	
	public int buttonWidth;
	public int buttonHeight;
	
	public float textX;
	public float textY;
	
	public AudioSample buttonHoverSound;
	public AudioSample buttonSelectedSound;
	public boolean isSamplePlaying = false;
	
	/**
	 * @param ix			X position.
	 * @param iy			Y position.
	 * @param iwidth		Width.
	 * @param iheight		Height.
	 * @param icolor		Normal color.
	 * @param ihighlight	Hover color.
	 * @param ifont			Text Font.
	 * @param itext			Text.
	 */
	public BVZRectButton(int ix, int iy, int iwidth, int iheight, int icolor, int ihighlight, PFont ifont, String itext, String bthover, String btselected){
		buttonX = ix;
		buttonY = iy;
		buttonWidth = iwidth;
		buttonHeight = iheight;
		baseColor = icolor;
		highlightColor = ihighlight;
		buttonFont = ifont;
		buttonText = itext;
		textX = buttonX + buttonWidth/2;
		textY = buttonY + buttonHeight/2;
		this.buttonHoverSound = btMinim.loadSample(bthover);
		this.buttonSelectedSound = btMinim.loadSample(btselected);

	}
	
	
	public BVZRectButton(String itext, String bthover, String btselected){
		buttonX = 50;
		buttonY = 50;
		buttonWidth = 80;
		buttonHeight = 30;
		baseColor = parent.color(111);
		highlightColor = parent.color(200);
		buttonFont = parent.createFont("Arial", 10, true);
		buttonText = itext;
		textX = buttonX + buttonWidth/2;
		textY = buttonY + buttonHeight/2;
		this.buttonHoverSound = btMinim.loadSample(bthover);
		this.buttonSelectedSound = btMinim.loadSample(btselected);

	}
	
	//	Image button
	public BVZRectButton(int ix, int iy, String bthover, String btselected, PImage btni, PImage btnhi){
		buttonX = ix;
		buttonY = iy;
		buttonWidth = 119;
		buttonHeight = 119;
		baseColor = parent.color(0, 0);
		highlightColor = parent.color(0, 0);
		buttonFont = parent.createFont("Arial", 10, true);
		buttonText = "";
		textX = buttonX + buttonWidth/2;
		textY = buttonY + buttonHeight/2;
		this.buttonHoverSound = btMinim.loadSample(bthover);
		this.buttonSelectedSound = btMinim.loadSample(btselected);
		buttonImage = btni;
		buttonHoverImage = btnhi;
	}
	
	public boolean over(){
		if(overRect(buttonX, buttonY, buttonWidth, buttonHeight)){
			over = true;
			if(!this.isSamplePlaying){
				this.buttonHoverSound.trigger();
				this.isSamplePlaying = true;
			}
				
//			this.buttonHoverSound.rewind();
			return true;
		}
		else{
			over = false;
			this.isSamplePlaying = false;
			return false;
		}
	}
	
	public void display(){
		parent.stroke(0);
		parent.fill(currentColor);
		parent.rect(buttonX, buttonY, buttonWidth, buttonHeight);
		parent.fill(0);
		parent.textFont(buttonFont);
		parent.textAlign(PConstants.CENTER);
		parent.text(buttonText, textX, textY);
	}
	
	public void display(int i){
		parent.imageMode(PConstants.CORNER);
		parent.pushMatrix();
		parent.translate(this.buttonX, this.buttonY);
		parent.image(this.currentImage, 0, 0, buttonWidth, buttonHeight);
		parent.popMatrix();
	}
	
}
